package com.ydtg.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.ydtg.bean.Picture;
import com.ydtg.dao.BaseDao;
import com.ydtg.dao.PictureDao;

public class PictureDaoImpl extends BaseDao implements PictureDao{
	public List<Picture> getall(Picture pic) {
		// TODO 自动生成的方法存根
		Connection conn = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		List<Picture> list = new ArrayList<Picture>();
		
		try {
			conn = getconnection();
			String sql = "select route from picture where 1=1";
			stmt = conn.prepareStatement(sql);
			rs = stmt.executeQuery();
			while (rs.next()) {
				Picture pet  = new Picture();
				pet.setRoute(rs.getString(1));
				list.add(pet);
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}finally {
			this.closeAll(conn, stmt, rs);
		}
		
		return list;
	}

	@Override
	public int add(Picture pet) {
		
		String psql = "insert into picture(name,route) "
				+ "values(?,?)";
		Object[] params = {pet.getName(),pet.getRoute()};
		
		int count=this.executeUpdate(psql, params);
		return count;
	}

	@Override
	public int updateByID(Picture pet) {
		
		String psql = "	UPDATE picture set name=?,route=? where id=?";
		Object[] params = {pet.getName(),pet.getRoute(),pet.getId()};
		int count =  this.executeUpdate(psql, params);
		return count;
	}

	@Override
	public int delByID(int id) {
		String psql = "	delete from picture where id=?";
		Object[] params = {id};
		int count = this.executeUpdate(psql, params);
		return count;
	}

	@Override
	public List<Picture> getTypefaceList(Picture pet) {
		
		return null;
	}
}
